package com.nwork.qingmanhua;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nwork.qingmanhua.utils.CommonUtils;


public class SplashActivity extends ActionBarActivity implements Animation.AnimationListener {
   private ImageView SplashImg1;
   private ImageView SplashImg2;
    private TextView SplashTxt1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        SplashImg1 = (ImageView) findViewById(R.id.splash_imgview);
        SplashImg2 = (ImageView) findViewById(R.id.splash_imgview2);
        SplashTxt1=(TextView)findViewById(R.id.splash_texttView);
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.splash_anim);
        Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.splash_anim2);
        Animation animation3 = AnimationUtils.loadAnimation(this, R.anim.splash_anim3);
        SplashImg1.setAnimation(animation);
        SplashImg2.setAnimation(animation2);
        SplashTxt1.setAnimation(animation3);
        animation.setAnimationListener(this);
    }


    @Override
    public void onAnimationStart(Animation animation) {
        //TODO 联网加载核心数据，然后跳转MainActivity
//        try {
//            new Thread().sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        //检测网络状态
        boolean available = CommonUtils.isNetWorkAvailable(this);
        if (available) {
            boolean wifi = CommonUtils.isWifi(this);
            if (wifi) {
                Toast.makeText(SplashActivity.this, "当前连接的是WIFI，请放心看吧", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SplashActivity.this, "当前是流量哦，请注意流量", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(SplashActivity.this, "亲 你的网络没有连接哦", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onAnimationEnd(Animation animation) {


        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
}
